package testing.views;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

/**
 * Servlet implementation class GetLocalDrugstores
 */
@WebServlet("/GetLocalDrugstores")
public class GetLocalDrugstores extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetLocalDrugstores() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		//Get parameters from request
		//Current Latitude, Longitude.
		
		
		//Retrieve the list of drug stores from our database
		//Name, Latitude, Longitude, and other properties
		
		
		//Convert all drug stores into JsonObject and add them into JsonArray
		JsonArray array = new JsonArray();
		for(int i=0; i<5; i++)
		{
			JsonObject drugstore = new JsonObject();
			drugstore.addProperty("Name", "Good Morning Pharmacy");
			//Please refer Google Maps API guide(See https://developers.google.com/maps). 
			drugstore.addProperty("Latitude", 30.7000d);
			drugstore.addProperty("Longitude", 11.4000d);
			array.add(drugstore);
		}
		
		//Put the list of drug stores into response.
		PrintWriter writer = response.getWriter();
		writer.print(array);
		
		//Now, android application has response to process this response.
		writer.flush();
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
